from time import sleep
import asyncio
from threading import Timer

from event_manager import Event, EventManager
from task import TaskDiscover, TaskPrinter

from config import EVENT_TOPIC_TASK_RECEIVED, DEVICE_ID


def start():
    # 实例化监听器
    printer = TaskPrinter()

    # 实例化事件操作函数
    eventManager = EventManager()

    # 绑定事件和监听器响应函数(新文章)
    eventManager.AddEventListener(EVENT_TOPIC_TASK_RECEIVED, printer.execute)

    # 启动事件管理器，启动事件处理线程
    eventManager.Start()

    listener = TaskDiscover(eventManager, DEVICE_ID)

    # p_job = listener.QueryTask()
    try:
        asyncio.get_event_loop().run_until_complete(listener.QueryTask())
    except:
        pass


if __name__ == "__main__":
    start()
